home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / cml-098.lha / cml-0.9.8 / examples / ex-unique.sml < prev   
Encoding:
Text File  |  1990-11-06  |  557 b   |  25 lines

  1. (* ex-unique.sml
  2.  *
  3.  * COPYRIGHT (c) 1990 by John H. Reppy.  See COPYRIGHT file for details.
  4.  *)
  5.  
  6. (* BEGIN EXAMPLE *)
  7. structure UniqueId : UNIQUE_ID =
  8.   struct
  9.     datatype id = ID of int
  10.  
  11.     val idCh : id CML.chan = CML.channel ()
  12.  
  13.     fun server i = (CML.send (idCh, ID i);  server (i+1))
  14.  
  15.     fun nextId () = CML.accept idCh
  16.  
  17.     val _ = RunCML.logChannel ("UniqueId.idCh", idCh)
  18.  
  19.     val _ = RunCML.logServer ("UniqueId",
  20.               fn () => (CML.spawn (fn () => server 0); ()),
  21.           fn () => ())
  22.  
  23.   end (* structure UniqueId *)
  24. (* END EXAMPLE *)
  25.